package com.sail.www.client;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.HasWidgets;
import com.sail.www.client.ui.Page;
import com.sail.www.client.util.PagePath;

public class AppController implements ValueChangeHandler<String> {

	private HasWidgets hasWidgets;

	public AppController() {
		History.addValueChangeHandler(this);
	}

	@Override
	public void onValueChange(ValueChangeEvent<String> event) {
		String path = event.getValue();
		Page page = new Page(path, hasWidgets);
		page.go();
	}

	public void start(HasWidgets hasWidgets) {
		this.hasWidgets = hasWidgets;
		if ("".equals(History.getToken())) {
			History.newItem(PagePath.HomePage.toString());
		} else {
			History.fireCurrentHistoryState();
		}
	}

}
